<?php
use yii\helpers\Url;
use common\models\Word;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>移动首页</title>
<meta name="keywords" content="英语，雅思，托福" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<meta content="false" id="twcClient" name="twcClient" />
<link rel="stylesheet" type="text/css" href="/css/mobile.css" />
<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/js/ajax141212.js"></script>
</head>
<body>

<div style="width:100%;background-color:#EEE; margin-bottom:10px;">
  <div style=" margin:0px auto;">
    <a href="/">首页</a>
    <a href="/favorite/edit">知识添加</a> 
  </div>
</div>

<style>

body,button,input,select,textarea {font:16px/1.125 microsoft yahei,arial;color:#333;}


.questiondiv{


	margin:0px auto; 
	margin-top:1px; 
	width:100%; 
 

	background-color:#EEE;

}

.questiondiv span{

	
}

ul{margin:0;padding:0;list-style:none;}  


.rightnum{
	display:inline-block;
	padding:0px;
	width:50px; 
	height:28px; 
	font-size:18px;
	text-align:center;
}


</style>

<script type="text/javascript" src="/js/NoLimitCategory.js"></script>
<div style="margin:0px auto; width:100%; margin-bottom:10px;">
    <div>毕业/破冰/总量：<?php echo $graduatedcount." / ".$icebreaking." / ".$allword?></div>
</div>
<div style="margin:0px auto; width:100%; margin-bottom:10px;">
	<div>进行/未破：<?php echo ($icebreaking-$graduatedcount)." / ".($allword-$graduatedcount)?></div>
</div>
<div style="margin:0px auto; width:100%; margin-bottom:10px;"><!--
--><div style="display:inline-block; margin-left:10px; font-size:12px; vertical-align:top; width:65px; height:24px; padding-left:5px; background:#F0F0F0">
    <div style="display:inline-block; height:24px; line-height:24px;">显示全部</div><!--
 --><div style="display:inline-block; height:24px; line-height:24px; vertical-align:top; position:relative">
      <input id="graduated" type="checkbox"<?php if($graduated == 0)echo ' checked="checked"'?> style="position:absolute; top:6px" />
    </div><!--
--></div><!--

--><div style="display:inline-block; margin-left:5px;"><input type="button" value="查找" onClick="search()" style=" width:50px; height:24px;"/></div>
</div>
<?php

//pre($favorite);
	for($i=0; $i<count($favorite); $i++){
		
		$cname1 = empty($favorite[$i]["cname"]) ? "" : "[".$favorite[$i]["cname"]."]";
		$cname2 = empty($favorite[$i]["cname2"]) ? "" : "[".$favorite[$i]["cname2"]."]";
		$cname3 = empty($favorite[$i]["cname3"]) ? "" : "[".$favorite[$i]["cname3"]."]";
		$cname4 = empty($favorite[$i]["cname4"]) ? "" : "[".$favorite[$i]["cname4"]."]";
		$cname5 = empty($favorite[$i]["cname5"]) ? "" : "[".$favorite[$i]["cname5"]."]";
		
		$word = empty($favorite[$i]["word"]) ? $favorite[$i]["w_word"] : $favorite[$i]["word"];
		$ipa_en = empty($favorite[$i]["ipa_en"]) ? stripcslashes($favorite[$i]["w_ipa_en"]) : stripcslashes($favorite[$i]["ipa_en"]);
		$ipa_us = empty($favorite[$i]["ipa_us"]) ? stripcslashes($favorite[$i]["w_ipa_us"]) : stripcslashes($favorite[$i]["ipa_us"]);
		$trans = empty($favorite[$i]["trans"]) ? $favorite[$i]["w_trans"] : $favorite[$i]["trans"];
		
		$correct_write = $favorite[$i]["understand_correct"];
		
		$color = \common\components\Common::getRightColor($correct_write);
		
		$curtime = time();
		
		$last_right_time = $favorite[$i]["understand_correct_at"];

		$locktime = \common\components\Common::getLocktime($correct_write);
		
		if($last_right_time+$locktime > $curtime){
			$questioncolor = '#BBB';
		}else{
			$questioncolor = '#000';
		}
		
		$trans_arr = explode('|', $trans);

		if(!empty($favorite[$i]["answer"])){
			$answer = $favorite[$i]["answer"];
		}else{
			$answer = '<a href="'.Url::to(['/word/detail', 'id'=>$favorite[$i]["id"]]).'"><h1>'.$word.'</h1></a>';

			if(!empty($ipa_en)){
				$answer .= '英<span style="font-family:lucida sans unicode, arial, sans-serif;">'.stripcslashes($ipa_en).'</span>';
			}

			if(!empty($ipa_us)){
				$answer .= '　美<span style="font-family:lucida sans unicode, arial, sans-serif;">'.stripcslashes($ipa_us).'</span>';
			}

			$trans_str = '';
			if(count($trans_arr) > 0){
				$trans_str = implode('<br>', $trans_arr);
				$answer .= '<br><br>'.$trans_str;
			}

		}

?>

<div class="questiondiv" onClick="downlist(this)">
  <span style="width:50px; text-align:center"><?php echo $favorite[$i]["id"]?></span>  
  <span style="width:820px; color:<?php echo $questioncolor?>">
  <?php echo $favorite[$i]["word"]?>
  </span>
  <span class="rightnum"><strong style="color:<?php echo $color?>;"><?php echo $correct_write?></strong></span>  
</div>

<div style="margin:0px auto; width:100%;display:none">
  <div style="padding:4px;">
  <?php echo $answer?>
  </div>
  <div style="margin:0px auto; width:100%; text-align:center; padding:0px; padding-bottom:8px;">
    <input type="button" value="顺序升一" onClick="exchangeAbove(<?php echo $favorite[$i]["id"]?>)"/> 
    <input type="button" value="顺序放后" onClick="orderlast(<?php echo $favorite[$i]["id"]?>)"/> 
    <input type="button" value="降低级别" onClick="understand_wrong(<?php echo $favorite[$i]["id"]?>)"/>
    <input type="button" value="回答正确" onClick="understand_correct(<?php echo $favorite[$i]["id"]?>)"/>
  </div>
</div>
<?php
	}
?>

<br>

<?php
	$pageurl = "?graduated=$graduated&mobile=$mobile&page=";
	
?>
	<div style=" margin:0px auto; width:100%; height:28px; line-height:28px; background-color:#EEE; text-align:center">
		<span>总数据:<?php echo $pv->dataCount?>条</span>
		<a href="<?php echo $pageurl."1"?>">首页</a>
		<a href="<?php echo $pageurl.$pv->prevPage?>">上一页</a>
		<span><?php echo $pv->currentPage."/".$pv->pageCount?></span>
		<a href="<?php echo $pageurl.$pv->nextPage?>">下一页</a>
		<a href="<?php echo $pageurl.$pv->pageCount?>">末页</a>
	</div>

<script language="javascript">

var page = <?php echo $pv->currentPage;?>;

function search(){
	var categorys = nlc.getSelects();
	var graduated = ($('#graduated').is(':checked')) ? 0 : 1;//0显示全部�?只显示未毕业�?

	var pageurl = "?"+"graduated="+graduated+"&mobile="+"true"+"&page="+page;

	window.location.href = pageurl;
}

//下拉菜单
function downlist(obj){
	var div = $(obj).next();
	var h = div.height();

	if(div.css('display') == 'none'){
		div.css('display', 'block');
		div.css('height', '0px');
		div.animate({height:h}, 500);
	}else{
		div.animate({height:'0px'}, 500, function(){
			div.css('display', 'none');
			div.height(h);//重新给它高度，否则下次展开的时候不灵，因为展开的时候这个高度需要读出来
		});
	}
}


function orderlast(id){
	if(confirm("确定降序？")){
		new Ajax().get({
			url : "<?php echo Url::to(['/practice/async-last'])?>"+"?id="+id,
			resultType : 'json',
			onLoaded : function(result){
				if(result.code == 1){
					alert("成功");
					window.location.reload();
				}else{
					alert(result.info);
				}
			}
		});
	}
}

function exchangeAbove(id){
    new Ajax().get({
        url : "<?php echo Url::to(['/practice/async-exchange-above'])?>"+"?id="+id+"&order=understand",
        resultType : 'json',
        onLoaded : function(result){
            if(result.code == 200){
                alert("成功");
                window.location.reload();
            }else{
                alert(result.info);
            }
        }
    });
}


//理解模式回答正确
function understand_correct(eid){
    console.log(eid);

    $.ajax({
        url : "<?php echo Url::to(['/practice/understand-correct'])?>",
        type : "GET",
        data : {
            eid : eid,
        },
        dataType : "json",
        success : function (result) {
            console.log(result);
            if(result.code == 200){
                alert("成功");
                window.location.reload();
            }else{
                alert(result.info);
            }
        }
    });

}

//理解模式回答错误
function understand_wrong(eid){

    $.ajax({
        url : "<?php echo Url::to(['/practice/understand-wrong'])?>",
        type : "GET",
        data : {
            eid : eid,
        },
        dataType : "json",
        success : function (result) {
            console.log(result);
            if(result.code == 200){
                alert("成功");
                window.location.reload();
            }else{
                alert(result.info);
            }
        }
    });

}

</script>
<br>
</div>
</body>
</html>